package ljl.alg.wangzheng_camp.round1.bitwise;

public class _191_count_1 {
    
    public int hammingWeight1(int n) {
        return Integer.bitCount(n);
    }
    
    /**
     * 果然又错了我透
     * 还是不能眼高手低
     * */
    public int hammingWeight2(int n) {
        int res = 0;
        // 这万不可写成 n > 0
        while (n != 0) {
            n &= n - 1;
            res++;
        }
        return res;
    }
    
}
